var express=require('express')
var Router=express.Router()
var db=require('../../tools/database/index.js')

var checkToken=require('../../tools/checkToken/index.js')
var redis=require('../../tools/redis/index.js')
var db=require('../../tools/database/index.js')
var getUserInfo=require('../../tools/NameList/index.js')

var admin=require('./admin.js')
var client=require('./client.js')
 //商家||管理员
Router.use('/getdata',async (req,res)=>{
	//检测地址是否存在问题
	var isAddress=await checkToken(req);
	if(!isAddress){
		res.send({
			state:404,
			data:'地址存在问题'
		})
	}else{
		
		//获取用户
		var user
		try{
			user=getUserInfo(req);
		}catch(e){
			res.send({
				state:404
			})
			console.log('解析错误')
			return;
		}
			var table;
			req.user=user
			//（商家/管理员）|| 用户
			if(user.Grade === "<manger>"){
				table=db.merchants;
				admin(req,res,table)
			}else{
				table=db.clients;
				client(req,res,table)
			}
	}
})
module.exports=Router